// index.js
// 获取应用实例
const app = getApp()
import config from '../../utils/config'
Page({
    data: {
        value: '',
        pageNum: 1,
        infoCardList: [],
        isover: false,
        rotate: false,
        selected: '起点查询',
        
    },
    rotateElement(e) {
        this.setData({
            rotate: !this.data.rotate
        })
    },
    handleClick(event) {
        const item = event.target.dataset.name; // 获取事件源上的自定义数据
        console.log('点击了子元素', item);
        this.setData({
            selected: item
        })
        this.rotateElement()
    },
    getInfo: (data, that) => {

        wx.request({
            url: `${config.baseUrl}/selectItem`,
            method: 'GET',
            data: data,
            success: (res) => {
                console.log('res', res);
                that.setData({
                    infoCardList: res.data.data
                })
            }
        })

    },
    debounceSearch(e) {
        this.setData({
            value: e.detail.value
        })
        const data = {
            selectMessage: this.data.value,
            selectType: this.data.selected
        }
       this.getInfo(data,this)
    },
    onLoad() {
        this.getInfoCard()

    },

    getInfoCard() {
        let that = this
        wx.request({
            url: `${config.baseUrl}/getInfoCard`,
            method: 'GET',
            data: {
                pageNum: that.data.pageNum
            },
            success: res => {   
                that.setData({
                    pageNum: that.data.pageNum + 1
                })
                if (res.data.code == 200) {
                    let list = that.data.infoCardList;
                    list = list.concat(res.data.data)
                    that.setData({
                        infoCardList: list
                    })
                } else {
                    that.setData({
                        isover: true
                    })
                }
            }
        })
    },
    onChange(e) {
        console.log(e.detail);
    },
    onShow() {
        this.getTabBar().init();
        this.onPullDownRefresh();
    },
    onReachBottom() {
        if (!this.data.isover) {
            this.getInfoCard()
        }
       
    },
    onPullDownRefresh(){
        this.setData({
            pageNum:1,
            infoCardList:[]
        })
        this.getInfoCard()
        wx.stopPullDownRefresh()
    }

})
